package com.zg.scf.web;

import cn.hutool.core.util.PhoneUtil;
import com.zg.common.core.R;
import com.zg.scf.domain.req.ScfSmsValidCodeReq;
import com.zg.scf.service.ScfSmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"短信接口"})
@RestController
@RequiredArgsConstructor
public class ScfSmsController {

    private final ScfSmsService scfSmsService;

    @ApiOperation("发送短信验证码")
    @GetMapping("/un/sms/sendCode")
    public R<Void> sendCode(String phone) {
        if (PhoneUtil.isMobile(phone)) {
            return R.error("请输入正确的手机号");
        }
        scfSmsService.sendCode(phone);
        return R.success();
    }

    @ApiOperation("验证短信验证码")
    @PostMapping("/sms/validCode")
    public R<Void> validCode(ScfSmsValidCodeReq req) {
        scfSmsService.validCode(req);
        return R.success();
    }
}
